package pers.muci.moudles.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * ClassName: MyCommandRunner
 * Description:配置项目启动后打开浏览器
 * date: 2021/10/9 10:09
 *
 * @author muci
 * @since JDK 1.8
 */
@Component
public class MyCommandRunner implements CommandLineRunner {

    @Value("${spring.web.loginurl}")
    private String loginUrl;

    @Value("${spring.auto.openurl}")
    private boolean isOpen;


    @Override
    public void run(String... args) throws Exception {
        if (isOpen){
            System.out.println("自动加载指定页面");
            try {
                Runtime.getRuntime().exec("cmd /c start  "+ loginUrl);
            }catch (Exception e){
                e.printStackTrace();
                System.out.println("页面加载异常");
            }
        }
    }
}
